using UnityEngine;

public class DoorEve : MonoBehaviour
{
    public Animator anim;
    bool playerNearby = false;

    void Start()
    {
    }

    void Update()
    {
        // 检测F键是否被按下，并且玩家在门附近
        if (Input.GetKeyDown(KeyCode.F) && playerNearby)
        {
            anim.SetBool("open", !anim.GetBool("open"));
        }
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("玩家靠近门");
            playerNearby = true;
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("玩家离开门");
            playerNearby = false;
        }
    }
}